

import 'package:zcw_eyepetizer/http/http_manager.dart';
import 'package:zcw_eyepetizer/http/url.dart';
import 'package:zcw_eyepetizer/model/common_item.dart';
import 'package:zcw_eyepetizer/utils/toast_util.dart';
import 'package:zcw_eyepetizer/viewmodel/base_change_notifier.dart';
import 'package:zcw_eyepetizer/widget/loading_state_widget.dart';

class VideoDetailViewModel extends BaseChangeNotifier {
    List<Item> itemList = [];
    late int _videoId;

    void loadVideoData(int id) {
        _videoId = id;
        // https://baobab.kaiyanapp.com/api/v4/video/related?id=266986
        HttpManager.requestData('${Url.videoRelatedUrl}$id').then((res) {
                Issue issue = Issue.fromJson(res);
        itemList = issue.itemList;
        viewState = ViewState.done;
    }).catchError((e) {
                ZcwToast.showError(e.toString());
        viewState = ViewState.error;
    }).whenComplete(() => notifyListeners());
    }

    void retry() {
        viewState = ViewState.loading;
        notifyListeners();
        loadVideoData(_videoId);
    }
}